|
|
|
|
|
|
|
Once this line appears in a C program or header file, it is thereafter possible to declare variables of type unsigned char by using the new type definition BYTE. Thus, the following two statements are identical: |
|
|
|
|
|
|
|
|
unsigned char myChar;
BYTE myChar; |
|
|
|
|
|
|
|
|
defines LPSTR as a pointer to a characterwhich, as you may recall, is how C also refers to strings. That's why LPSTR often appears as a parameter in an API declaration to indicate a string parameter. The parameter is a pointer to a string, which is the same thing as a pointer to a char if the character that is pointed to is the first character in a NULL-terminated string. |
|
|
|
|
|
|
|
|
By convention, derived data types use all uppercase characters. |
|
|
|
|
|
|
|
|
The typedef statement can also be used to define pointers to functions. A pointer to a function is like any other pointer in that it contains the address of a location in memory. The only difference is that a pointer to a function points to memory that contains executable code rather than data. The Visual Basic AddressOf operator can be used to obtain a pointer to a function in a standard module. |
|
|
|
|
|
|
|
|
A typedef statement that defines a pointer to a function looks like this: |
|
|
|
|
|
|
|
|
typedef void (*MYFUNCTIONTYPE)(); |
|
|
|
|
|
|
|
|
This defines MYFUNCTIONTYPE as a data type that points to a function that has no parameters and no return value. |
|
|
|
|
|
|
|
|
typedef long (*MYFUNCTIONTYPE)(short a, char *b); |
|
|
|
|
|
|
|
|
This defines MYFUNCTIONTYPE as a data type that points to a function that takes two parameters, a 16-bit integer and a 32-bit pointer to a character array, and returns a long value. |
|
|
|
|
|
|
|
|
The C language also has a macro capability in which you can define a keyword to be replaced by other text at compile time. These definitions are specified using the #define statement. Thus, the line: |
|
|
|
|
|